package com.林子祺.CAT旅游系统.view.tour.buy;

import com.林子祺.CAT旅游系统.controller.contentmanagement.Charge;
import com.林子祺.CAT旅游系统.controller.contentmanagement.OrderTicket;
import com.林子祺.CAT旅游系统.entity.login.LoginStatus;
import com.林子祺.CAT旅游系统.view.Menu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static java.lang.Integer.parseInt;

public class BuyTicket {

    public static void buy(){
        JFrame jf = new JFrame("请输入要买的门票的id：");
        jf.setSize(280, 150);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(null);

        final JTextField textField = new JTextField(8);
        textField.setLocation(0,0);
        textField.setSize(100,30);
        textField.setFont(new Font(null, Font.PLAIN, 12));
        panel.add(textField);

        JButton btn = new JButton("提交");
        btn.setLocation(100,0);
        btn.setSize(70,30);
        btn.setFont(new Font(null, Font.PLAIN, 10));
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String s = textField.getText();
                int MyInt = Integer.parseInt(s);
                OrderTicket.buyTicket(LoginStatus.name,MyInt);
                jf.dispose();
            }
        });
        panel.add(btn);

        JButton btn1 = new JButton("返回");
        btn1.setLocation(180,0);
        btn1.setSize(70,30);
        btn1.setFont(new Font(null, Font.PLAIN, 10));
        btn1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Menu.menu();
                } catch (AWTException ex) {
                    throw new RuntimeException(ex);
                }
                jf.dispose();
            }
        });
        panel.add(btn1);

        jf.setContentPane(panel);
        jf.setVisible(true);
    }

}
